/**
  * @Description: WoShop商城
  * @Author: 梧桐
  * @Copyright: 武汉一一零七科技有限公司©版权所有
  * @Link: www.s1107.com
  * @Contact: QQ:2487937004
  */
<template>
	<view class="index_class">
		<view class="bottom_img">
		  <image :src="goodsInfo.thumb_url" />
		
		  <view style="padding:0 40upx 0 20upx;flex:1">
		    <view class="introduce">{{goodsInfo.goods_name}}</view>
		    <view class="arrt-str">{{goodsInfo.goods_attr_str}}</view>
		  </view>
		   
		   
		    
		</view>
		<view class="rele-areat">
			<!--  app 端状态栏站位 -->
			<view class="input-text">
				<textarea v-model="textValue" name="" id="" cols="30" rows="10" placeholder="想要说的话"></textarea>
				<view class="text-number">{{textValue.length}}/800</view>
			</view>

			<view class="addfile">
				<view class="grace-add-file">
					<view class="grace-add-btn" @tap="addImg" v-if="btnImg">
						<view>+</view>
						<view>添加照片</view>
					</view>
					<view class="garce-items" v-for="(item, index) in imgLists" :key="index">
						<image :src="item" mode="widthFix" :data-imgurl="item" @tap="showImgs"></image>
						<view class="grace-close" @tap="removeImg" :id="'grace-items-img-'+index"></view>
					</view>
				</view>
			</view>
			<view class="shoppin">
				<view class="feedback-star-view">
					<text>商品评分</text>
					<uni-rate class="unirate" value="5" @change="changestar"></uni-rate>
				</view>
			</view>
			<view class="person-button" style="margin:0;background-color:#fff;padding-top:40upx">
				<button type="warn" class="btn" @click="getaddthorder">发 布</button>
			</view>
		</view>
	</view>
</template>


<script>
	import uniRate from '../../components/uni-rate/uni-rate'
	var maxNum = 9,
		_self;
	export default {
		data() {
			return {
				order_id: '',
				list: [1, 2, 3, 4, 5, 6],
				imgLists: [],
				btnImg: true,
				graceSelectTips: [{
						name: 'php',
						value: '0',
						checked: true
					},
					{
						name: '.net',
						value: '1',
						checked: false
					},
					{
						name: 'java',
						value: '2',
						checked: false
					},
					{
						name: 'nodeJs',
						value: '3',
						checked: false
					},
					{
						name: '其他',
						value: '4',
						checked: false
					},
					{
						name: '其他',
						value: '5',
						checked: false
					},
					{
						name: '其他',
						value: '6',
						checked: false
					},
				],
				textValue: '',
				goodsList: [],
				goddsName: [],
				pickValue: [],
				starValue: '5',
				isClick: true
			}
		},
		components: {
			uniRate
		},
		onLoad(option) {
			_self = this;
			this.getOrderID(option);

		},

		methods: {

			getOrderID(option) {
				this.order_id = option.id;
				console.log(this.order_id)
			},
			changestar(e) {
				this.starValue = e.value;
				console.log(this.starValue);
			},
			addImg: function() {
				var num = maxNum - _self.imgLists.length;
				if (num < 1) {
					return false;
				}

				uni.chooseImage({
					count: num,
					sizeType: ['compressed'],
					success: function(res) {
						_self.imgLists = _self.imgLists.concat(res.tempFilePaths);
						if (_self.imgLists.length >= maxNum) {
							_self.btnImg = false;
						}
						uni.hideLoading();

					}
				});
			},
			removeImg: function(e) {
				var index = e.currentTarget.id.replace('grace-items-img-', '');
				_self.imgLists.splice(index, 1);
				_self.imgLists = _self.imgLists;
				if (_self.imgLists.length < maxNum) {
					_self.btnImg = true;
				}
			},
			showImgs: function(e) {
				var currentImg = e.currentTarget.dataset.imgurl;
				uni.previewImage({
					urls: this.imgLists,
					current: currentImg
				})
			},
			/**
			 * 图片上传
			 */
			getuploadspic() {
				if (this.imgLists.length == 0) {
					this.$toast('请先上传图片')
					return false
				}
				return new Promise(resolve => {
					this.$http.getuploadspic(this.imgLists, '/api/find/uploadspic').then(res => {
						if (res.status == 200) {
							resolve(res.images)
						}
					})
				})
			},
			/**
			 *提交审核
			 */
			async getaddthorder() {
				if (this.textValue == '') {
					this.$toast('请输入评价内容')
					return false
				}
				if (this.isClick == false) {
					return false;
				}

				if (this.isClick) {
					this.isClick = false;
					let str = await this.getuploadspic()
					console.log(str)
					let data = {
						describe: this.textValue,
						star: this.starValue,
						pic: str.join(','),
						order_id: this.order_id,
					}
					this.$loading();
					this.$http.getaddfind(data).then(res => {
						if (res.status == 200) {
							this.$toast(res.mess)
						}
					});

				}

				setTimeout(() => {
					this.isClick = true;
					this.getback()
				}, 1500)
			},



		}
	}
</script>

<style>

</style>
